import Common from "../Common/Common";
import DataManager from "./DataManager";
import DataStorage from "./DataStorage";
import UIManager from "./UIManager";

cc.Class({
    extends: cc.Component,

    properties: {
        canvas: {
            default: null,
            type: cc.Node,
            tooltip: '场景画布'
        },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    init(){
      
        DataStorage.getlocalData();
        DataManager.MaxLevel = Object.keys( DataManager.GameConfig.DinosaurConfig).length;
        appGame.audioMgr.playBGM("bg", true);
        // //完成所有关卡重置数据
        if (DataStorage.localData.level > DataManager.MaxLevel) {
            DataStorage.initStorage();

        } else {
            //判断有无随机数据id数组
            // if (!DataStorage.localData.musicArr) {
            //     DataStorage.localData.musicArr = Common.randArray(DataManager.GameConfig.musicConfig.length);
            //     DataStorage.setLocalData("musicArr", DataStorage.localData.musicArr);
            // }
            //设置当前关卡数
            DataManager.currLevel = DataStorage.localData.level ? DataStorage.localData.level : 1;
        }
        // console.log(DataStorage.localData);
        // console.log(DataManager.GameConfig);
        //初始化游戏 关闭加载界面 打开大厅界面
        UIManager.instance.load.close();
        UIManager.instance.hall.open();
    },

    // update (dt) {},
});
